package com.mb.app.appused.views;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;

/**
 * 选项组
 * 
 * @author xhwwzd
 *
 */
public class CustomGroup extends ScrollView {

	LinearLayout parent;
	Context context;

	public List<LinearLayout> groups = new ArrayList<LinearLayout>();

	public CustomGroup(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		initView(context);
	}

	public CustomGroup(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		initView(context);
	}

	public CustomGroup(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		// TODO Auto-generated constructor stub
		initView(context);
	}

	@SuppressLint("NewApi")
	public CustomGroup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
		super(context, attrs, defStyleAttr, defStyleRes);
		// TODO Auto-generated constructor stub
		initView(context);
	}

	/**
	 * 初始内容
	 * 
	 * @param context
	 */
	void initView(Context context) {
		this.context = context;
		parent = new LinearLayout(this.context);
		parent.setOrientation(LinearLayout.VERTICAL);
		this.addView(parent);

	}

	public ViewGroup addGroup() {
		LinearLayout group = new LinearLayout(this.context);
		group.setOrientation(LinearLayout.VERTICAL);
		group.setLayoutParams(getFallWidth());
		groups.add(group);
		parent.addView(group);
		return group;
	}

	public void addItem(int group, int layout) {
		if (layout == -1)
			return;
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(layout, null);
		groups.get(group).addView(view);
	}

	LayoutParams getFall() {
		LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		return lp;
	}

	LayoutParams getFallWidth() {
		LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		return lp;
	}

	LayoutParams getFallWidth(int height) {
		LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		lp.height = height;
		return lp;
	}

	LinearLayout.LayoutParams getFall(float weigth) {
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT, weigth);
		return lp;
	}

	LayoutParams getWidthHeight(int w, int h) {
		LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		lp.width = w;
		lp.height = h;
		return lp;
	}

	LayoutParams getWrap() {
		LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		return lp;
	}
}
